package com.tt.manage.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tt.manage.pojo.Item;
import com.tt.manage.service.ItemService;

@Controller
public class ItemController {
	@Autowired
	private ItemService itemService;
	@RequestMapping("/item/{id}")
	@ResponseBody
	public Object getItemById(@PathVariable Long id){
		try {
			return itemService.getItemById(id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	/***
	 * 列表显示商品数据
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/item/list")
	@ResponseBody
	public Object getItemList(int page,int rows){
		try {
			List<Item> list= itemService.getItemsByPage(page,rows);
			Map<String,Object> map=new HashMap<>();
			map.put("total", itemService.getItemsCount());
			map.put("rows", list);
			return map;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
}
